1930B - Permutation Printing - CodeForces Solution


constructive algorithms math

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
using namespace std;
#define sortdt(v) sort(v.begin(),v.end())
#define sortdt_d(v) sort(v.begin(),v.end(),greater<int>())
#define ll long long
#define ld long double
#define forl(i,k,n) for(long long i=k;i<n;i++)
#define rforl(i,k,n) for(long long i=n-1;i>=k;i--)
#define vll vector <long long>
#define vch vector <char>
#define vpll vector<pair<long long, long long>>
#define printy cout<<"YES"<<endl;
#define printn cout<<"NO"<<endl;
#define takearr(a,n) forl(i,0,n){cin>>a[i];}
#define pb(vec,i) vec.push_back(i)

ll getarrsum(ll arr[], ll n)
{
    ll sum=0;
    forl(i,0,n)
    {
        sum+=arr[i];
    }
    return sum;
}

vll presum(ll arr[], ll n)
{
    vll vec(n);
    vec[0]=arr[0];
    forl(i,1,n)
    {
        vec[i]=arr[i]+vec[i-1];
    }
    return vec;
}

vll sufsum(ll arr[], ll n)
{
    vll vec(n);
    vec[n-1]=arr[n-1];
    rforl(i,0,n-1)
    {
        vec[i]=arr[i]+vec[i+1];
    }
    return vec;
}

void solve()
{
    ll n;
    cin>>n;
    int i=1;
    int j=n;
    while (i<j)
    {
        cout<<i<<" "<<j<<" ";
        i++;
        j--;
    }
    if (i==j)
    {
        cout<<i<<" ";
    }
    cout<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    ll t;
    cin>>t;
    while(t--)
    {
        solve();
    }
}


Comments

Submit
0 Comments
More Questions

545B - Equidistant String
1244C - The Football Season
1696B - NIT Destroys the Universe
1674A - Number Transformation
1244E - Minimizing Difference
1688A - Cirno's Perfect Bitmasks Classroom
219A - k-String
952A - Quirky Quantifiers
451B - Sort the Array
1505H - L BREAK into program
171E - MYSTERIOUS LANGUAGE
630D - Hexagons
1690D - Black and White Stripe
1688D - The Enchanted Forest
1674C - Infinite Replacement
712A - Memory and Crow
1676C - Most Similar Words
1681A - Game with Cards
151C - Win or Freeze
1585A - Life of a Flower
1662A - Organizing SWERC
466C - Number of Ways
1146A - Love "A"
1618D - Array and Operations
1255A - Changing Volume
1710C - XOR Triangle
415C - Mashmokh and Numbers
8A - Train and Peter
591A - Wizards' Duel
1703G - Good Key Bad Key